

//
//  SearchHeadView.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/11/26.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "SearchHeadView.h"
@interface SearchHeadView()<UIScrollViewDelegate>
@property(nonatomic,strong) UIScrollView *scrollView;

@property(nonatomic,strong) MCButton *preMCBtn;
@end
@implementation SearchHeadView
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        CGFloat w = kWidth/3;
        NSArray *titles = @[@"服务",@"需求",@"店铺"];
        for (int i = 0; i < 3; i++) {
            self.mcBtn = [[MCButton alloc]initWithFrame:CGRectMake(w*i, 0, w, kHeight)];
            [self addSubview:self.mcBtn];
            [self.mcBtn setTitle:titles[i] forState:UIControlStateNormal];
            self.mcBtn.tag = i+1;
            if (i == 0) {
                [self.mcBtn setImage:[ImageColorHelper createImageWithColor:kOrangeBg] forState:UIControlStateNormal];
                [self.mcBtn setTitleColor:kLabel16Color forState:UIControlStateNormal];
                self.preMCBtn = self.mcBtn;
            }else{
                [self.mcBtn setImage:[UIImage new] forState:UIControlStateNormal];
                [self.mcBtn setTitleColor:kLabel153Color forState:UIControlStateNormal];
            }
            self.mcBtn.buttonStyle = imageNormalBottom;
            self.mcBtn.titleLabel.font = [UIFont systemFontOfSize:14];
            [self.mcBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
            self.mcBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
            [self.mcBtn setTitleColor:kLabel153Color forState:UIControlStateNormal];
        }
    }
    return self;
}
-(void)clickBtn:(MCButton *)clickBtn
{
    [self.preMCBtn setImage:[UIImage new] forState:UIControlStateNormal];
    [self.preMCBtn setTitleColor:kLabel153Color forState:UIControlStateNormal];
    self.scrollView.contentOffset = CGPointMake(clickBtn.tag*kWidth, 9);
    [clickBtn setImage:[ImageColorHelper createImageWithColor:kOrangeBg] forState:UIControlStateNormal];
    [clickBtn setTitleColor:kLabel16Color forState:UIControlStateNormal];
    self.preMCBtn = clickBtn;
    if ([self.delegate respondsToSelector:@selector(searchHeadView:withBtn:)]) {
        [self.delegate searchHeadView:self withBtn:clickBtn];
    }
    
}
@end
